﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ExameRegister.Views
{
    public class GroupBox : ContentControl
    {

        private RectangleGeometry FullRect;
        private RectangleGeometry HeaderRect;
        private ContentControl HeaderContainer;

        public GroupBox()
        {
            DefaultStyleKey = typeof(GroupBox);
            this.SizeChanged += GroupBox_SizeChanged;
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            FullRect = (RectangleGeometry)GetTemplateChild("FullRect");
            HeaderRect = (RectangleGeometry)GetTemplateChild("HeaderRect");
            HeaderContainer = (ContentControl)GetTemplateChild("HeaderContainer");
            HeaderContainer.SizeChanged += HeaderContainer_SizeChanged;
        }

        public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register("Header", typeof(object), typeof(GroupBox), null);
        public object Header
        {
            get { return GetValue(HeaderProperty); }
            set { SetValue(HeaderProperty, value); }
        }

        public static readonly DependencyProperty NameProperty = DependencyProperty.Register("Name", typeof(object), typeof(GroupBox), null);
        public object Name
        {
            get { return GetValue(NameProperty); }
            set { SetValue(NameProperty, value); }
        }





        public string Header1
        {
            get { return (string)GetValue(Header1Property); }
            set { SetValue(Header1Property, value); }
        }

        // Using a DependencyProperty as the backing store for Header1.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty Header1Property =
            DependencyProperty.Register("Header1", typeof(string), typeof(GroupBox), null);



        public string Header2
        {
            get { return (string)GetValue(Header2Property); }
            set { SetValue(Header2Property, value); }
        }

        // Using a DependencyProperty as the backing store for Header2.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty Header2Property =
            DependencyProperty.Register("Header2", typeof(string), typeof(GroupBox), null);

        

        



        public static readonly DependencyProperty HeaderTemplateProperty = DependencyProperty.Register("HeaderTemplate", typeof(DataTemplate), typeof(GroupBox), null);
        public DataTemplate HeaderTemplate
        {
            get { return (DataTemplate)GetValue(HeaderTemplateProperty); }
            set { SetValue(HeaderTemplateProperty, value); }
        }

        private void GroupBox_SizeChanged(object sender, System.Windows.SizeChangedEventArgs e)
        {
            FullRect.Rect = new Rect(new Point(), e.NewSize);
        }

        private void HeaderContainer_SizeChanged(object sender, System.Windows.SizeChangedEventArgs e)
        {
            HeaderRect.Rect = new Rect(new Point(HeaderContainer.Margin.Left, 0), e.NewSize);
        } 
    }
}
